/**
 * Created by jt on 2017/5/8.
 */
import "./index.less";
// import "../../../unit/common/js/common/main_portal.js";

var projId = getArgs().id;
var username = sessionStorage.getItem('username');
var reseIndex = sessionStorage.getItem('reseIndex');

jQuery.ajax({
    url: HOST_ADDR+'/cpmp/bidProjOffMngForPortal/viewProjDtl/'+projId,
    type: 'get',
    dataType: 'json',
    contentType:"application/json",
    success: function(resp){
        if (!resp.success) {
            alert(resp.msgCod+' '+resp.msgInf);
            return;
        }

        var bidRngTyp='非定向招标';
        var splrs=[];
        if (resp.data.bidProjOff.bidRngTyp == 1) {
            bidRngTyp='定向招标';
            if (resp.data.splrs.length !=0) {
                for (var i = 0;i<resp.data.splrs.length;i++) {
                    splrs.push(resp.data.splrs[i].splrNam);
                }
            }
        }
        var currTyp='';
        if (resp.data.bidProjOff.currTyp == 'USD') {
            currTyp='美元';
        } else if (resp.data.bidProjOff.currTyp == 'RMB') {
            currTyp='人民币';
        }
        var dpstFlg='不需要',pubPriFlg='否';
        if (resp.data.bidProjOff.dpstFlg == 1) {
            dpstFlg='需要';
        }
        if (resp.data.bidProjOff.pubPriFlg == 1) {
            pubPriFlg='是';
        }
        var ntcPubTim='',bidOpenTim='',bidEndTim='',projMemo='',projNbr='';
        if (resp.data.bidProjOff.ntcPubTim != null&&resp.data.bidProjOff.ntcPubTim !='') {
            ntcPubTim = (new Date(resp.data.bidProjOff.ntcPubTim)).Format("yyyy-MM-dd hh:mm:ss");
        }
        if (resp.data.bidProjOff.bidOpenTim != 'null'&&resp.data.bidProjOff.bidOpenTim !='') {
            bidOpenTim = (new Date(resp.data.bidProjOff.bidOpenTim)).Format("yyyy-MM-dd hh:mm:ss");
        }
        if (resp.data.bidProjOff.bidEndTim != 'null'&&resp.data.bidProjOff.bidEndTim !='') {
            bidEndTim = (new Date(resp.data.bidProjOff.bidEndTim)).Format("yyyy-MM-dd hh:mm:ss");
        }
        if (resp.data.bidProjOff.projMemo != null&&resp.data.bidProjOff.projMemo !='') {
            var projMemo = resp.data.bidProjOff.projMemo;
        }
        if (resp.data.bidProjOff.projNbr != null &&resp.data.bidProjOff.projNbr !='') {
            projNbr=resp.data.bidProjOff.projNbr;
        }

        console.log(resp)
        if (username != null && username != '') {  // 登录后才可查看
            var atches = resp.data.atches;
            if ((atches!=null && atches!='undefined') && atches.length > 0){
                for (var i= 0;i<atches.length;i++) {
                    jQuery('.bacisPanel').append('<div class="controls atchDiv"><span src="'+atches[i].atchUrl+'">'+atches[i].atchNam+'</span>' +
                        '&emsp;<a target="_blank" href="'+HOST_FILE+atches[i].atchUrl+'">查看</a></div>');
                }
            }
        }

        jQuery('.projTitle').html(resp.data.bidProjOff.projNam+'<div class="service-block-v5 margin-top-20">' +
            '<p class="fontsize-14">'+ntcPubTim+'</p></div>');

        var matTyp = resp.data.bidProjOff.matTyp;
        if(resp.data.matTypDesc!=null && resp.data.matTypDesc!=''){
            matTyp = resp.data.matTypDesc;
        }
        jQuery('.basicInfo').append('<tbody><tr>' +
            '<td width="16%">项目名称：</td><td colspan="2">'+resp.data.bidProjOff.projNam+'</td> ' +
            '<td width="16%">项目编号：</td> <td colspan="2">'+projNbr+'</td></tr><tr>' +
            '<td width="16%">招标单位：</td><td colspan="2">'+resp.data.bidProjOff.bidDpt+'</td>' +
            '<td width="16%">招标单位地址：</td><td colspan="2">'+resp.data.bidProjOff.bidDptAddr+'</td></tr><tr>' +
            '<td width="16%">联系人：</td><td colspan="2">'+resp.data.bidProjOff.ctct+'</td>' +
            '<td width="16%">联系电话：</td><td colspan="2">'+resp.data.bidProjOff.ctctTel+'</td></tr><tr>' +
            '<td width="16%">是否需要投标保证金：</td><td colspan="2">'+dpstFlg+'</td>'+
            '<td width="16%">是否需要公开招标价格：</td><td colspan="2">'+pubPriFlg+'</td></tr>'+
            '<tr><td width="16%">投标保证金（元）：</td><td colspan="2">'+resp.data.bidProjOff.bidDpst+'</td>' +
            '<td width="16%">币种：</td><td colspan="2">'+currTyp+'</td></tr>'+
            '<tr><td width="16%">物料品类：</td><td colspan="5">'+matTyp+'</td></tr><tr>' +
            '<td width="16%">投标开标时间：</td><td colspan="2">'+bidOpenTim+'</td>'+
            '<td width="16%">投标截止时间：</td><td colspan="2">'+bidEndTim+'</td></tr><tr>' +
            '<td>招标范围类型：</td><td colspan="2">'+bidRngTyp+'</td>' +
            '<td width="16%">指定招标供应商：</td><td colspan="2">'+splrs+'</td></tr><tr>' +
            '<td>备注信息：</td><td colspan="5">'+projMemo+'</td></tr></tbody>');
        jQuery('.bidBok').html(resp.data.bidProjOff.bidBok);

        if (resp.data.bidProjOff.projSts == '20') {
           jQuery('.bid_project_time').html('<a href="apply_bid_offline.html?id='+resp.data.bidProjOff.projId+'"  role="button" class="scrap btn green-stripe apply"><i class="icon-user"></i> 我要申请</a>');
        }
    },
    error:function(err){
        alert('系统错误！');
    }
});